home *** CD-ROM | disk | FTP | other *** search
/ A Teacher's Guide to the Holocaust / A Teacher's Guide to the Holocaust.iso / data / people / scripts / elemtextclass.js < prev    next >
Text File  |  1999-12-05  |  5KB  |  198 lines

  1. // Copyright 1998,1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //Constructs a text entry element
  4. function MM_text(theParent, theName, theInitialValue) {
  5.   // properties
  6.   this.initialValue = theInitialValue?theInitialValue:'';
  7.   this.value = null;
  8.   this.disabled = true;
  9.   
  10.   this._parent = theParent;
  11.   this._name = theName;
  12.   this._obj = '';
  13.   
  14.   this.c = new Array();
  15.  
  16.   // member functions
  17.   this.init = MM_textInit;
  18.   this.reset = MM_textReset;
  19.   this.enable = MM_textEnable;
  20.   this.disable = MM_textDisable;
  21.   this.setDisabled = MM_textSetDisabled;
  22.   this.update = MM_textUpdate;
  23.   this.redraw = MM_textRedraw;
  24.   this.setValue = MM_textSetValue;
  25.   this.focus = MM_textFocus;
  26. }
  27.  
  28. //Initializes the element
  29. function MM_textInit() {
  30.   with (this) _obj = MM_intFindObject(_parent._self + _name + "Inp");
  31. }
  32.  
  33. //Resets the element
  34. function MM_textReset() {
  35.   with (this) {
  36.     _parent.disabled ? disable() : enable();
  37.     setValue(initialValue);
  38.   }
  39. }
  40.  
  41. //Enables the element
  42. function MM_textEnable() {
  43.   var i;
  44.   if (this._obj) with (this) {
  45.     disabled = false;
  46.     for (i in c) if (i != 'length') c[i].disabled = false;
  47.     setValue(_obj.value);
  48.   }
  49. }
  50.  
  51. //Disables the element
  52. function MM_textDisable() {
  53.   this.disabled = true;
  54.   this.redraw();
  55. }
  56.  
  57. //Calls the approppriate disable or enable function
  58. function MM_textSetDisabled(theDisabled) {
  59.   if (theDisabled) this.disable();
  60.   else this.enable();
  61. }
  62.  
  63. //Called by onClick event to update this elements value
  64. //We also store the object reference of the control, so that
  65. // we can reset it later.
  66. function MM_textUpdate() {
  67.   var isChanged = '';
  68.   if (!this.disabled) with (this) {
  69.     _obj.value = MM_textStripSpaces(_obj.value);
  70.     isChanged = (value != _obj.value);
  71.     value = _obj.value;
  72.     for (var i in c) if (i != 'length') c[i].validValue();
  73.     if (isChanged && this.onChange != null) onChange(_parent._self+_name, value);
  74.     _parent.update();   // call the parent's update
  75.   }
  76. }
  77.  
  78. // Sets the text value
  79. function MM_textRedraw() {
  80.   if (this._obj) with (this) {
  81.     if (_obj.disabled != null) _obj.disabled = disabled;
  82.     if (_obj.value != null) _obj.value = value;
  83.   }
  84. }
  85.  
  86. function MM_textSetValue(theValue) {
  87.   var isChanged = '';
  88.   with (this) {
  89.     theValue = MM_textStripSpaces(theValue);
  90.     isChanged = (value != theValue);
  91.     value = theValue;
  92.     redraw();
  93.     for (var i in c) if (i != 'length') c[i].validValue();
  94.     if (isChanged && this.onChange != null) onChange(_parent._self+_name, value);
  95.     _parent.update(true);  // update int, no judge
  96.   }
  97. }
  98.  
  99. function MM_textFocus() {
  100.   if (this.disabled) with (this._parent)
  101.     if (browserIsNS && browserVersion >= 4.0 && osIsWindows) this._obj.blur();
  102. }
  103.  
  104.  
  105. //////////////////////////////////////////
  106. //Create a string choice object
  107. function MM_textComp(theParent, theElement, theName,
  108.                      theExpectedValue, theIsCorrect, theScore,
  109.                      theMatchCase, theMatchAll)
  110. {
  111.   // properties
  112.   this.expectedValue = theExpectedValue;
  113.   this.isCorrect = theIsCorrect;
  114.   this.score = theScore;
  115.   this.selected = false;
  116.   this.disabled = false;
  117.   
  118.   this.matchCase = theMatchCase;
  119.   this.matchAll = theMatchAll;
  120.   
  121.   this._elem = eval(theParent._self+".e['"+theElement+"']");
  122.   this._isChoice = true;
  123.  
  124.   // methods
  125.   this.validValue = MM_textCompValidValue;
  126.   this.setSelected = MM_textCompSetSelected;
  127.   this.setDisabled = MM_textCompSetDisabled;
  128.   this.deencrypt = MM_textDeencrypt;
  129.  
  130. }
  131.  
  132. function MM_textCompValidValue() {
  133.   var theValue, expValue;
  134.   with (this) {
  135.     selected = false;
  136.     if (!disabled) {
  137.       theValue = _elem.value;
  138.       expValue = deencrypt(expectedValue);
  139.  
  140.       if (!matchCase) {
  141.         theValue = theValue.toUpperCase();
  142.         expValue = expValue.toUpperCase();
  143.       }
  144.  
  145.       if (theValue != '') {
  146.         if (matchAll)  selected = (theValue == expValue);
  147.         else  selected = (theValue.indexOf(expValue) != -1);
  148.   } } }
  149.   return this.selected;
  150. }
  151.  
  152. function MM_textCompSetSelected(theSelected) {
  153.   with (this) {
  154.     if (theSelected) {
  155.       _elem.setValue(deencrypt(expectedValue));
  156.     } else {
  157.       selected = false;
  158.       _elem._parent.update(true); // update int, no judge
  159.   } }
  160. }
  161.  
  162. function MM_textCompSetDisabled(theDisabled) {
  163.   with (this) {
  164.     disabled = theDisabled;
  165.     validValue();
  166.     _elem._parent.update(true); // update interaction, no judge
  167.   }
  168. }
  169.  
  170. function MM_textDeencrypt(theStr) {
  171.   var decipher='',i,key,clength,part='-###-',keyOffsetObscure,keyOffset='',hyphen;
  172.   
  173.   if (theStr.indexOf(part)!=-1) {
  174.     strStart = theStr.indexOf(part)+part.length;
  175.   hyphen=theStr.indexOf('-');
  176.     key = theStr.substring(0,hyphen);
  177.   keyOffsetObscure=theStr.substring(hyphen+1, theStr.indexOf('-',hyphen+1));
  178.     for (i=keyOffsetObscure.length-1;i>=0;i--)
  179.     keyOffset+=keyOffsetObscure.charAt(i);
  180.     clength = key-keyOffset;
  181.     retVal = theStr.substring(strStart, theStr.length);
  182.   for (i=0;i<retVal.length;i+=(clength+1))
  183.     decipher=decipher+retVal.charAt(i);
  184.  
  185.   retVal = decipher;
  186.   }
  187.   else retVal = theStr;
  188.     
  189.   return retVal;
  190. }
  191.  
  192. function MM_textStripSpaces(theStr) {
  193.   var c,b=0,e=theStr.length-1,E=e;
  194.   while (b<E&&((c=theStr.charAt(b))==" " || c=="\r" || c=="\n")) b++;
  195.   while (e>0&&((c=theStr.charAt(e))==" " || c=="\r" || c=="\n")) e--;
  196.   return theStr.substring(b,e+1);
  197. }
  198.